<?php


namespace App\Controller\client;


use App\Common\Res;
use App\Controller\AbstractController;
use App\Rpc\client\impl\UserDeviceImpl;
use Hyperf\Utils\ApplicationContext;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use HyperfException\Json;

class UserDeviceController extends AbstractController
{
    use Res;

    /**
     * 设备登录
     * @return array
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function login(): array
    {
        $params = $this->request->all();
        $res = ApplicationContext::getContainer()->get(UserDeviceImpl::class)->login($params);
        if ($res['code'] < 0)
            return $res['data'];
        return $res;
    }

    /**
     * 判断设备是否登录
     * @return array
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function isLogin(): array
    {
        $params = $this->request->all();
        $res = ApplicationContext::getContainer()->get(UserDeviceImpl::class)->isLogin($params);
        if ($res['code'] < 0)
            return $res['data'];
        return $res;
    }

}